package com.ikas.ai.server.module.data.service;

import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ikas.ai.server.module.data.dao.BaseMeteDao;
import com.ikas.ai.server.module.data.model.BaseMete;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * @author hu.bowei@ikasinfo.com
 * @date 2024-04-11- 18:28
 */
@Service
public class BaseMeteService extends ServiceImpl<BaseMeteDao, BaseMete> {

    @Autowired
    private BaseMeteDao baseMeteDao;

    public BaseMete selectByMachNoMeteCodeMeteId(String machineNo, String meteCode, Long meteId) {
        LambdaQueryChainWrapper<BaseMete> lambdaQueryChainWrapper = new LambdaQueryChainWrapper<>(baseMeteDao);
        List<BaseMete> list = lambdaQueryChainWrapper
                .eq(StringUtils.isNotBlank(machineNo), BaseMete::getMachineNo, machineNo)
                .eq(StringUtils.isNotBlank(meteCode), BaseMete::getMeteCode, meteCode)
                .eq(Objects.nonNull(meteId), BaseMete::getMeteId, meteId)
                .list();
        return CollectionUtils.isEmpty(list) ? null : list.get(0);
    }
}
